package com.shuaiche.yeguan.util;

import android.content.Context;
import android.os.CountDownTimer;
import android.widget.Button;

import com.shuaiche.yeguan.R;

import androidx.core.content.ContextCompat;


/**
 *
 * Created by baoyb on 2017/10/31.
 * 获取验证码倒计时
 */
public class SCCodeCountDownUtils extends CountDownTimer{

    private Context context;
    private Button btnGetCode;
    private long nSecond = 0;
    /**是否处于获取短信验证码的过程中*/
    public static boolean isGetSmsCode;

    public SCCodeCountDownUtils(Context context, long millisInFuture, long countDownInterval, Button btnGetCode) {
        super(millisInFuture, countDownInterval);
        this.context = context;
        this.btnGetCode = btnGetCode;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        btnGetCode.setEnabled(false);
        nSecond = millisUntilFinished / 1000;
        btnGetCode.setTextColor(ContextCompat.getColor(context, R.color.text_gray));
        btnGetCode.setText(nSecond + "S");
    }

    @Override
    public void onFinish() {
        btnGetCode.setText("重发验证码");
        btnGetCode.setTextColor(ContextCompat.getColor(context, R.color.text_black));
        btnGetCode.setEnabled(true);
        nSecond = 0;
        isGetSmsCode = false;
    }
}
